<!-- 三级分类组件，用到来copy -->

<!-- <template>
    <div>
      <el-form :inline="true" :disabled="disabled">
        <el-form-item label="一级分类">
          <el-select @change="changeCategory1Id" v-model="category1Id">
            <el-option v-for="v of category1List" :key="v.id" :label="v.name" :value="v.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select @change="changeCategory2Id" v-model="category2Id">
            <el-option v-for="v of category2List" :key="v.id" :label="v.name" :value="v.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三级分类">
          <el-select v-model="category3Id">
            <el-option v-for="v of category3List" :key="v.id" :label="v.name" :value="v.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
</template>
<script lang="ts">
import {defineComponent} from 'vue';

export default defineComponent({
  name: 'CategorySelector'
})
</script>
<script lang="ts" setup>
import {storeToRefs} from 'pinia';
import {useCategorySelectorStore} from '@/stores/categorySelector';

// 定义一个 prop ：disabled ，如果 disabled 值为 true 则禁用表单
withDefaults(defineProps<{
  disabled: boolean
}>(), {
  disabled: false
})

// 初始化仓库
const categorySelectorStore = useCategorySelectorStore();

// 解构仓库中的数据（并使其联动）
const {category1Id, category2Id, category3Id, category1List, category2List, category3List} = storeToRefs( categorySelectorStore );

// 进入组件后调用获取一级分类数据
categorySelectorStore.getCategory1List();

// console.log(`category1List`, category1List);

// 监听 一级分类 change 事件
const changeCategory1Id = () => {
  // console.log('category1Id', category1Id.value);
  // 获取二级分类数据
  categorySelectorStore.getCategory2List();
}

const changeCategory2Id = () => {
  // console.log('category2Id', category2Id.value);
  // 获取三级分类数据
  categorySelectorStore.getCategory3List();
}
</script> -->